<template>
  <div class="app-container">
    <el-form :model="dataForm" class="cus_form">
      <el-row :gutter="20">
        <el-col :span="14">
          <el-form-item>
            <el-input v-model="dataForm.IndexCondition" size="mini" placeholder="名称/代码" clearable>
              <el-button slot="append" icon="el-icon-search" @click="getDataList()" />
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      v-loading="dataListLoading"
      :data="dataList"
      class="eltable"
      :height="viewHeight"
      style="width: 100%;"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" header-align="left" align="left" width="30" />
      <el-table-column v-if="false" prop="Instancenodeid" header-align="left" align="left" width="80" label="ID" />
      <el-table-column prop="Processcode" header-align="left" align="left" min-width="200" label="流程代码" />
      <el-table-column prop="Processname" header-align="left" align="left" min-width="200" label="流程名称" />
      <el-table-column prop="Nodename" header-align="left" align="left" min-width="120" label="当前节点" />
      <el-table-column prop="Begindate" header-align="left" align="left" min-width="120" label="开始时间" />
      <el-table-column fixed="right" header-align="center" align="center" width="160" label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="forwardHandler(scope.row.Instancenodeid, scope.row.Instanceid)">
            <i class="el-icon--right el-icon-edit" />&nbsp;处理
          </el-button>
          <el-button type="text" @click="deleteHandle(scope.row.Id)">
            <i class="el-icon--right el-icon-view" />&nbsp;查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row justify="end">
      <el-col style="text-align: right;">
        <el-pagination
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :page-count="totalPage"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
        />
      </el-col>
    </el-row>
    <!-- <div v-if="forwardDialog">
      <ForwardNode ref="forwardnode" @refreshDataList="getDataList()" />
    </div> -->
    <el-dialog
      v-if="forwardDialog"
      title="处理流程"
      :close-on-click-modal="false"
      width="70%"
      class="abow_dialog"
      :visible.sync="forwardDialog"
    >
      <ForwardNodes :id="id" :instance-id="instanceId" @close="closedialog" />
    </el-dialog>
  </div>
</template>
<script>
// import ForwardNode from './components/forwardnode'
import { getTodoProcess } from '@/api/workflowprocess'
import ForwardNodes from './components/forwardnodes'
export default {
  components: {
    ForwardNodes
    // ForwardNode
  },
  data() {
    return {
      forwardDialog: false,
      viewHeight: this.$store.state.common.documentClientHeight - 210,
      dataListLoading: false,
      dataForm: {
        IndexCondition: ''
      },
      id: '',
      instanceId: '',
      total: 1,
      totalPage: 1,
      pageSize: 10,
      pageIndex: 1,
      dataList: [],
      multipleSelection: []
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      this.dataListLoading = true
      const condition = {
        limit: this.pageSize,
        offset: this.pageSize * (this.pageIndex - 1)
      }
      if (this.dataForm.IndexCondition) {
        condition.query = `Code.contains:${this.dataForm.IndexCondition},Condition_Join:or,Name.contains:${this.dataForm.IndexCondition}`
      }
      getTodoProcess(condition).then((data) => {
        this.dataList = data.data
        this.totalPage = data.count % this.pageSize === 0 ? (data.count / this.pageSize) : (Math.floor(data.count / this.pageSize) + 1)
        this.total = data.count
        this.dataListLoading = false
      }).catch(() => {
        this.dataListLoading = false
      })
    },
    //
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    closedialog() {
      this.forwardDialog = false
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 / 修改
    forwardHandler(id, Instanceid) {
      this.id = id
      this.instanceId = Instanceid
      this.forwardDialog = true
      // this.$nextTick(() => {
      // this.$refs.forwardnode.init(id, Instanceid)
      // })
    }
  }
}
</script>
